﻿using SmartSiteManagementSystem.Models.DTO;
using SmartSiteManagementSystem.Models.Equipment;
using SmartSiteManagementSystem.Models.Material;
using SmartSiteManagementSystem.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSiteManagementSystem.Models.WorkTask
{

    [Serializable]
    public class TaskInfo
    {

        #region 数据库存储字段

        /// <summary>
        ///任务唯一标识  数据库自增字段
        /// </summary>
        private int _taskId;
        /// <summary>
        /// 任务序号 未排序的序号
        /// </summary>
        public int TaskId
        {
            get { return _taskId; }
            set { _taskId = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        private string _taskName;

        /// <summary>
        /// 任务名字
        /// </summary>
        public string TaskName
        {
            get { return _taskName; }
            set { _taskName = value; }
        }



        /// <summary>
        ///
        /// </summary>
        private int _taskSetId;
        /// <summary>
        /// 任务集Id
        /// </summary>
        public int TaskSetId
        {
            get { return _taskSetId; }
            set { _taskSetId = value; }
        }


        /// <summary>
        ///
        /// </summary>
        private int _batchId;
        /// <summary>
        /// 任务批次
        /// </summary>
        public int BatchId
        {
            get { return _batchId; }
            set { _batchId = value; }
        }


        private int _demandMaterialId;
        /// <summary>
        ///  任务需要的物料Id
        /// </summary>
        public int DemandMaterialId
        {
            get { return _demandMaterialId; }
            set { _demandMaterialId = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private double _demandingPlacePositionX;
        /// <summary>
        /// 需求地  坐标X  快照 存储需求地的坐标
        /// </summary>
        public double DemandingPlacePositionX
        {
            get { return _demandingPlacePositionX; }
            set { _demandingPlacePositionX = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        private double _demandingPlacePositionY;
        /// <summary>
        /// 需求地  坐标Y  快照 存储需求地的坐标
        /// </summary>
        public double DemandingPlacePositionY
        {
            get { return _demandingPlacePositionY; }
            set { _demandingPlacePositionY = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        private double _demandingPlacePositionZ;
        /// <summary>
        /// 供应地  坐标Z 快照 存储需求地的坐标
        /// </summary>
        public double DemandingPlacePositionZ
        {
            get { return _demandingPlacePositionZ; }
            set { _demandingPlacePositionZ = value; }
        }

        /// <summary>
        ///
        /// </summary>
        private int _demandingPlaceId;
        /// <summary>
        /// 需求地ID 对应数据库的需求地  没有则是0
        /// </summary>
        public int DemandingPlaceId
        {
            get { return _demandingPlaceId; }
            set { _demandingPlaceId = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private DateTime _materialArrivalTime;
        /// <summary>
        /// 物料到达时间
        /// </summary>
        public DateTime MaterialArrivalTime
        {
            set { _materialArrivalTime = value; }
            get { return _materialArrivalTime; }
        }



        private int _weight;
        /// <summary>
        ///  权重
        /// </summary>
        public int Weight
        {
            get { return _weight; }
            set { _weight = value; }
        }

        private int _sla;
        /// <summary>
        ///  权重
        /// </summary>
        public int SLA
        {
            get { return _sla; }
            set { _sla = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private string _descript;

        /// <summary>
        /// 任务集描述
        /// </summary>
        public string Descript
        {
            get { return _descript; }
            set { _descript = value; }
        }

        /// <summary>
        /// 是否删除 逻辑删  1 删除 0 
        /// </summary>
        private bool _isDelete;

        public bool IsDelete
        {
            get { return _isDelete; }
            set { _isDelete = value; }

        }

        /// <summary>
        /// 
        /// </summary>
        private DateTime _createtime;
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime
        {
            set { _createtime = value; }
            get { return _createtime; }
        }

        private DateTime _updatetime;
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime
        {
            set { _updatetime = value; }
            get { return _updatetime; }
        }




        #endregion

        #region 虚拟字段

        /// <summary>
        /// 到达时间  时间戳 任务集开始与MaterialArrivalTime物料到达时间戳
        /// </summary>
        public double ArrivalTime { get; set; }

        /// <summary>
        /// 任务序号
        /// </summary>
        public int TaskOrderId { get; set; }

        /// <summary>
        /// 任务需要的物料     20220406 add
        /// </summary>
        public MaterialInfo DemandMaterial;



        /// <summary>
        /// 任务需要的物料 用户界面显示
        /// </summary>
        public string DemandMaterialStr;

        /// <summary>
        /// 需求地     20220406 add
        /// </summary>
        public DemandingPlaceInfo DemandingPlaceInfo;

        /// <summary>
        /// 供应地
        /// </summary>
        public PositionInfo DemandPosition
        {
            get
            {
                return new PositionInfo(this.DemandingPlaceId, this.DemandingPlacePositionX, this.DemandingPlacePositionY, this.DemandingPlacePositionZ);
            }
         }

        /// <summary>
        /// 
        /// </summary>
        public string DemandPositionPositionStr
        {
            get
            {
                return "(x:" + this.DemandPosition.x.ToString() + " y:" + this.DemandPosition.y.ToString() + " z:" + this.DemandPosition.z.ToString() + ")";
            }
        }

        /// <summary>
        /// 供应地
        /// </summary>
        public PositionInfo SupplyPosition { get; set; }

        /// <summary>
        /// 是否交叉任务 flase 不是  20220406 add
        /// </summary>
        public bool IsOverlappingTask;


        /// <summary>
        /// 根据需求地坐标计算出那个塔吊可以操作 如果集合只有1个 则只有一个塔可以操作
        /// 如果有多个，则任务属于交叉任务 20220406 add
        /// </summary>
        public IList<TowerCraneInfo> InitTowerCraneIdList;


        /// <summary>
        /// 最后确定那个塔吊做的ID  20220406 add
        /// </summary>
        public int AffirmatoryTowerCraneId;

        /// <summary>
        /// 供应地     20220406 add
        /// </summary>
        public SupplyingPlaceInfo SupplyingPlaceInfo;



        #region 排序使用属性
        /// <summary>
        /// 计算后的顺序
        /// </summary>
        public int FinalOrderId { get; set; }


        /// <summary>
        /// 塔吊执行任务的排序        20220406 add
        /// </summary>
        public int TowerCraneTaskInfoOrderId { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public double CompleteTime { get; set; }


        /// <summary>
        /// 是否迟到
        /// </summary>
        public bool isLate { get; set; }

        /// <summary>
        /// 优先值
        /// </summary>
        public double PriorityValue { get; set; }

        #region Pr  Pa Ph P Rdd
        /// <summary>
        /// 准备径向运动时间
        /// </summary>
        public double Pr { get; set; }


        /// <summary>
        /// 准备角行程时间
        /// </summary>
        public double Pa { get; set; }



        /// <summary>
        /// 准备垂直行程时间
        /// </summary>
        public double Ph { get; set; }



        /// <summary>
        /// 前一项任务的物料需求到此任务的物料供应地的准备时间
        /// </summary>
        public double P { get; set; }



        /// <summary>
        /// 开始加工时间
        /// </summary>
        public double starT { get; set; }

        /// <summary>
        /// 交货剩余时间 rdd
        /// </summary>
        public double Rdd { get; set; }



        /// <summary>
        /// 任务宽裕时间 SL
        /// </summary>
        public double SL { get; set; }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="position"></param>
        /// <param name="lastCompleteT">上一步完成时间</param>
        public void RecountPAndRddFuction(PositionInfo position, double lastCompleteT)
        {
            this.CompleteTime = 0;
            this.starT = lastCompleteT;
            this.Pr = CalculatePr(this.SupplyPosition, position, this.Vr);
            this.Pa = CalculatePa(this.SupplyPosition, position, this.Va);
            this.Ph = CalculatePh(this.SupplyPosition, position, this.Vh, this.VhLoadAndUloadDistance);
            this.P = CalculateP(this.Pr, this.Pa, this.Ph, 0.25f, 4f);
            this.CompleteTime = this.starT + this.ActionT + this.P;
            if (this.CompleteTime - this.Dd > 0)
            {
                this.isLate = true;
            }
            this.Rdd = CalculateRdd(this.Dd, this.starT);
            this.SL = CalculateSL(this.Dd, this.CompleteTime);
        }
        #endregion

        #endregion


        #endregion


        #region 需要初始化的固定变量

        /// <summary>
        /// 径向速度 eg 60m/min  60
        /// </summary>
        public double Vr { get; set; }

        /// <summary>
        ///角速度 eg 0.5m/min 0.5
        /// </summary>
        public double Va { get; set; }


        /// <summary>
        ///垂直行程速度 eg 136m/min 136
        /// </summary>
        public double Vh { get; set; }

        /// <summary>
        /// 垂直行程最小提升距离的总距离  eg 4
        /// </summary>
        public double VhLoadAndUloadDistance { get; set; }

        #endregion



        #region 自动计算属性
        /// <summary>
        /// 径向运动时间
        /// </summary>
        public double  Tr {
            get
            {
                return CalculateTr(this.SupplyPosition, this.DemandPosition, this.Vr);
            }
        }

        /// <summary>
        /// 角行程时间
        /// </summary>
        public double Ta
        {
            get
            {
                return CalculateTa(this.SupplyPosition, this.DemandPosition, this.Va);
            }
        }


        /// <summary>
        /// 垂直行程时间
        /// </summary>
        public double Th
        {
            get
            {
                return CalculateTh(this.SupplyPosition, this.DemandPosition, this.Vh,this.VhLoadAndUloadDistance);
            }
        }


        /// <summary>
        /// 操作时间
        /// </summary>
        public double ActionT
        {
            get
            {
                return CalculateT(this.Tr, this.Ta, this.Th,0.25f ,4f);
            }
        }


        /// <summary>
        /// 交货期
        /// </summary>
        public double Dd
        {
            get
            {
                return this.ArrivalTime+this.ActionT*this.SLA;
            }
        }


        #endregion

        #region Tr 径向 Ta 角 Th 垂直  T操作时间 Dd交货期 计算方法 

        /// <summary>
        /// 获取单个任务的径向运动时间Tr
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="vr">径向速度</param>
        /// <returns></returns>
        public double CalculateTr(PositionInfo supplyPosition, PositionInfo demandPosition, double vr)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && vr >= 0)
            {

                double supplyPositioXPow = Math.Pow(supplyPosition.x, 2.0); //物料地supplyPosition.x的平方
                double supplyPositioYPow = Math.Pow(supplyPosition.y, 2.0); //物料地supplyPosition.y的平方
                double supplyPositioXYPowSumSqrt = System.Math.Sqrt(supplyPositioXPow + supplyPositioYPow); //物料地supplyPosition.x的平方+物料地supplyPosition.y的平方 开根号。

                double demandPositionXPow = Math.Pow(demandPosition.x, 2.0); //目的地demandPosition.x的平方
                double demandPositionYPow = Math.Pow(demandPosition.y, 2.0); //目的地demandPosition.y的平方
                double demandPositionXYPowSumSqrt = System.Math.Sqrt(demandPositionXPow + demandPositionYPow); //目的地demandPosition.x的平方+目的地demandPosition.y的平方 开根号。

                double difference = System.Math.Abs(supplyPositioXYPowSumSqrt - demandPositionXYPowSumSqrt);//差的绝对值

                reslutVal = Math.Round(difference / vr, 2);//保留2位小数

            }
            return reslutVal;

        }

        /// <summary>
        /// 获取单个任务的角行程时间Ta
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="va">角速度</param>
        /// <returns></returns>
        public double CalculateTa(PositionInfo supplyPosition, PositionInfo demandPosition, double va)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && va >= 0)
            {
                double supplyPositionTanSupplyPositionA = 0F;
                if (supplyPosition.x != 0)
                {

                    double temSupplyPositionVar = Math.Round(supplyPosition.y / supplyPosition.x,2);
                    double supplyPositionTanSupplyPosition = Math.Atan(temSupplyPositionVar);
                    supplyPositionTanSupplyPositionA = supplyPositionTanSupplyPosition / Math.PI * 180;
                    supplyPositionTanSupplyPositionA = Math.Round(supplyPositionTanSupplyPositionA, 2);


                }
                double demandPositionTanSupplyPositionA = 0F;
                if (demandPosition.x != 0)
                {
                    double temDemandPositionVar = Math.Round(demandPosition.y / demandPosition.x, 2);
                    double demandPositionTanSupplyPosition = Math.Atan(temDemandPositionVar);
                    demandPositionTanSupplyPositionA = demandPositionTanSupplyPosition / Math.PI * 180;
                    demandPositionTanSupplyPositionA = Math.Round(demandPositionTanSupplyPositionA, 2);

                }

                double difference = System.Math.Abs(demandPositionTanSupplyPositionA - supplyPositionTanSupplyPositionA);//差的绝对值
                reslutVal = Math.Round(difference / va, 2);//保留2位小数
            }
            return reslutVal;
        }


        /// <summary>
        /// 获取单个任务的吊钩水平行程时间Th
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="vh">垂直行程速度</param>
        /// <param name="loadAndUloadDistance">最小提升高度 加载与卸载的距离</param>
        /// <returns></returns>
        public double CalculateTh(PositionInfo supplyPosition, PositionInfo demandPosition, double vh, double loadAndUloadDistance)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && vh >= 0)
            {
                double difference = System.Math.Abs(supplyPosition.z - demandPosition.z);//差的绝对值
                reslutVal = Math.Round((difference + loadAndUloadDistance) / vh, 2);//保留2位小数
            }
            return reslutVal;
        }

        /// <summary>
        /// 获取单个任务的操作时间T
        /// </summary>
        /// <param name="tr">径向操作时间</param>
        /// <param name="ta">角行程时间</param>
        /// <param name="th">垂直行程时间</param>
        /// <param name="radio"></param>
        /// <param name="t">4min</param>
        /// <returns></returns>
        public double CalculateT(double tr, double ta, double th, double radio, double t)
        {
            double reslutVal = 0f;
            double maxTrTa = MathsTool.MaxFun(tr, ta);
            double minTrTa = MathsTool.MinFun(tr, ta);
            double sumMaxTrTaMinTrTa = maxTrTa + minTrTa;
            double maxSumMaxTrTaMinTrTaAndTh = MathsTool.MaxFun(sumMaxTrTaMinTrTa, th);
            double minSumMaxTrTaMinTrTaAndTh = MathsTool.MinFun(sumMaxTrTaMinTrTa, th);
            reslutVal = Math.Round(maxSumMaxTrTaMinTrTaAndTh + radio * minSumMaxTrTaMinTrTaAndTh + t, 2);
            return reslutVal;
        }

        #endregion

        #region Pr Pa Ph P Rdd
        /// <summary>
        /// Pr
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="vr">径向速度</param>
        /// <returns></returns>
        public double CalculatePr(PositionInfo supplyPosition, PositionInfo demandPosition, double vr)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && vr >= 0)
            {

                double supplyPositioXPow = Math.Pow(supplyPosition.x, 2.0); //物料地supplyPosition.x的平方
                double supplyPositioYPow = Math.Pow(supplyPosition.y, 2.0); //物料地supplyPosition.y的平方
                double supplyPositioXYPowSumSqrt = System.Math.Sqrt(supplyPositioXPow + supplyPositioYPow); //物料地supplyPosition.x的平方+物料地supplyPosition.y的平方 开根号。

                double demandPositionXPow = Math.Pow(demandPosition.x, 2.0); //目的地demandPosition.x的平方
                double demandPositionYPow = Math.Pow(demandPosition.y, 2.0); //目的地demandPosition.y的平方
                double demandPositionXYPowSumSqrt = System.Math.Sqrt(demandPositionXPow + demandPositionYPow); //目的地demandPosition.x的平方+目的地demandPosition.y的平方 开根号。

                double difference = System.Math.Abs(supplyPositioXYPowSumSqrt - demandPositionXYPowSumSqrt);//差的绝对值

                reslutVal = Math.Round(difference / vr, 2);//保留2位小数

            }
            return reslutVal;

        }

        /// <summary>
        /// Pa
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="va">角速度</param>
        /// <returns></returns>
        public double CalculatePa(PositionInfo supplyPosition, PositionInfo demandPosition, double va)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && va >= 0)
            {
                double supplyPositionTanSupplyPositionA = 0F;
                if (supplyPosition.x != 0)
                {

                    double temSupplyPositionVar = Math.Round(supplyPosition.y / supplyPosition.x, 2);
                    double supplyPositionTanSupplyPosition = Math.Atan(temSupplyPositionVar);
                    supplyPositionTanSupplyPositionA = supplyPositionTanSupplyPosition / Math.PI * 180;
                    supplyPositionTanSupplyPositionA = Math.Round(supplyPositionTanSupplyPositionA, 2);


                }
                double demandPositionTanSupplyPositionA = 0F;
                if (demandPosition.x != 0)
                {
                    double temDemandPositionVar = Math.Round(demandPosition.y / demandPosition.x, 2);
                    double demandPositionTanSupplyPosition = Math.Atan(temDemandPositionVar);
                    demandPositionTanSupplyPositionA = demandPositionTanSupplyPosition / Math.PI * 180;
                    demandPositionTanSupplyPositionA = Math.Round(demandPositionTanSupplyPositionA, 2);

                }

                double difference = System.Math.Abs(demandPositionTanSupplyPositionA - supplyPositionTanSupplyPositionA);//差的绝对值
                reslutVal = Math.Round(difference / va, 2);//保留2位小数
            }
            return reslutVal;
        }


        /// <summary>
        /// Ph
        /// </summary>
        /// <param name="supplyPosition">物料地</param>
        /// <param name="demandPosition">目的地</param>
        /// <param name="vh">垂直行程速度</param>
        /// <param name="loadAndUloadDistance">最小提升高度 加载与卸载的距离</param>
        /// <returns></returns>
        public double CalculatePh(PositionInfo supplyPosition, PositionInfo demandPosition, double vh, double loadAndUloadDistance)
        {
            double reslutVal = 0f;
            if (supplyPosition != null && demandPosition != null && vh >= 0)
            {
                double difference = System.Math.Abs(supplyPosition.z - demandPosition.z);//差的绝对值
                reslutVal = Math.Round((difference + loadAndUloadDistance) / vh, 2);//保留2位小数
            }
            return reslutVal;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pr"></param>
        /// <param name="pa"></param>
        /// <param name="ph"></param>
        /// <param name="radio"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public double CalculateP(double pr, double pa, double ph, double radio, double t)
        {
            double reslutVal = 0f;
            double maxTrTa = MathsTool.MaxFun(pr, pa);
            double minTrTa = MathsTool.MinFun(pr, pa);
            double sumMaxTrTaMinTrTa = maxTrTa + minTrTa;
            double maxSumMaxTrTaMinTrTaAndTh = MathsTool.MaxFun(sumMaxTrTaMinTrTa, ph);
            double minSumMaxTrTaMinTrTaAndTh = MathsTool.MinFun(sumMaxTrTaMinTrTa, ph);
            reslutVal = Math.Round(maxSumMaxTrTaMinTrTaAndTh + radio * minSumMaxTrTaMinTrTaAndTh + t, 2);
            return reslutVal;
        }


        /// <summary>
        /// 计算交货剩余时间 rdd
        /// </summary>
        /// <param name="dd"></param>
        /// <param name="startT">开始加工时间</param>
        /// <returns></returns>
        public double CalculateRdd(double dd,double startT)
        {
            double ddCutTime = dd - startT;
            double reslutVal = MathsTool.MaxFun(ddCutTime, 0);
            return reslutVal;
        }


        /// <summary>
        /// 计算任务宽裕时间SL
        /// </summary>
        /// <param name="dd"></param>
        /// <param name="completeT">完成时间</param>
        /// <returns></returns>
        public double CalculateSL(double dd, double completeT)
        {
            double ddCutTime = dd - completeT;
            double reslutVal = MathsTool.MaxFun(ddCutTime, 0);
            return reslutVal;

        }


        #endregion



        /// <summary>
        /// 重新计算
        /// </summary>
        /// <param name="_taskOrderId">任务序号</param>
        /// <param name="_arrivalTime">到达时间</param>
        /// <param name="_supplyPlaceList">供应地集合</param>
        /// <param name="_vr">径向速度 eg 60m/min  60</param>
        /// <param name="_va">角速度  eg 0.5m/min 0.5</param>
        /// <param name="_vh">垂直行程速度 eg 136m/min 136</param>
        /// <param name="_vhLoadAndUloadDistance">垂直行程最小提升距离的总距离  eg 4</param>
        /// <param name="_towerCraneInfoList">塔吊集合</param>
        /// <param name="_material">随机生成的需要的物料</param>
        public void InitTaskInfo(int _taskOrderId
            ,double _arrivalTime
            , IList<SupplyingPlaceInfo> _supplyPlaceList
            ,double _vr
            , double _va
            , double _vh
            ,double _vhLoadAndUloadDistance
            , IList<TowerCraneInfo> _towerCraneInfoList
            ,MaterialInfo _material
            )
        {
            this.FinalOrderId = 0;
            this.TaskOrderId = _taskOrderId;
            this.ArrivalTime = _arrivalTime;
            this.Vr = _vr;
            this.Va = _va;
            this.Vh = _vh;
            this.VhLoadAndUloadDistance = _vhLoadAndUloadDistance;
            //20220406 add
            this.DemandMaterial = _material;
            this.DemandMaterialId = _material.MaterialId;
            PositionInfo zeroPosition = new PositionInfo(0, 0, 0, 0);
            this.SupplyPosition = zeroPosition;
            //end 20220406 add
            this.PriorityValue = 0f;
            this.isLate = false;
            this.starT = 0f;
            #region 根据需求地坐标判断那几个塔吊可做任务是否交叉任务 20220406 add
            this.InitTowerCraneIdList = new List<TowerCraneInfo>();
            foreach (TowerCraneInfo towerCrane in _towerCraneInfoList)
            {
                if(IfIsInCircular(towerCrane.Position.x,
                    towerCrane.Position.y,
                    towerCrane.OperatingRadius,
                    this.DemandPosition.x,
                     this.DemandPosition.y
                    ))
                {
                    this.InitTowerCraneIdList.Add(towerCrane);
                }
                
            }
            if(this.InitTowerCraneIdList.Count>1)
            {
                this.IsOverlappingTask = true;
            }
            else
            {
                this.IsOverlappingTask = false;
            }

            #endregion

            RecountPAndRddFuction(zeroPosition,0);

        }

        /// <summary>
        /// 判断点是否在圆内或圆上  20220406 add
        /// </summary>
        /// <param name="circular_x">圆心坐标X</param>
        /// <param name="circular_y">圆心坐标Y</param>
        /// <param name="circular_r">圆半径</param>
        /// <param name="point_x">点坐标X</param>
        /// <param name="point_y">点坐标Y</param>
        /// <returns></returns>
        public bool IfIsInCircular(double circular_x,double circular_y,double circular_r,double point_x,double point_y)
        {
            bool back = false;
            double resultVal=(point_x - circular_x) * (point_x - circular_x) + (point_y - circular_y) * (point_y - circular_y);
            if(resultVal<= circular_r* circular_r)
            {
                back = true;
            }
            return back;
        }



        /// <summary>
        /// 重写输出方法
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {

            return string.Format(
               "任务序号:{1} 任务批次:{2} 到达时间:{3} 供应地:{4} 需求地:{5} 任务权重:{6} 宽裕度系数:{7} Tr:{8} Ta:{9} Th:{10} 操作时间:{11} 交货期:{12}  Pr:{13} Pa:{14} Ph:{15} P:{16} Rdd:{17} 任务完成时间:{18} 优先函数值:{19} 是否迟到:{20} SL:{21} 任务开始时间:{22} 任务需要物料:{23} 是否交叉任务:{24} 需求地坐标在塔吊圈内集合：{25}"
               , this.FinalOrderId
               , this.TaskOrderId.ToString()
                , this.BatchId
                , this.ArrivalTime
                , this.SupplyPosition.Id.ToString() + "( x=" + this.SupplyPosition.x.ToString() + " y=" + this.SupplyPosition.y.ToString() + " z=" + this.SupplyPosition.z.ToString() + ")"
                , this.DemandPosition.Id.ToString() + "( x=" + this.DemandPosition.x.ToString() + " y=" + this.DemandPosition.y.ToString() + " z=" + this.DemandPosition.z.ToString() + ")"
                , this.Weight
                , this.SLA
                , this.Tr
                , this.Ta
                 , this.Th
                 , this.ActionT
                 , this.Dd
                 , this.Pr
                 , this.Pa
                 , this.Ph
                 , this.P
                 , this.Rdd
                 , this.CompleteTime
                 , this.PriorityValue
                 , this.isLate == true ? "是" : "否"
                 , this.SL
                 , this.starT
                 , this.DemandMaterial.MaterialName+"(Id:"+this.DemandMaterial.MaterialId+")"
                 , this.IsOverlappingTask == true ? "是" : "否"
                 , GettowerCraneInfoListStr(this.InitTowerCraneIdList)
                );

        }


        public string GettowerCraneInfoListStr(IList<TowerCraneInfo> towerCraneInfoList)
        {
            string back = "";
            if(towerCraneInfoList.Count>0)
            {
                foreach(TowerCraneInfo item in towerCraneInfoList)
                {
                    back = back + "吊(Id:" + item.TowerCraneId + " x:" + item.Position.x.ToString() + " y:" + item.Position.y + " r:" + item.OperatingRadius.ToString() + ")";
                }
            }
            return back;
        }
    }
}
